package com.lzy.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lzy.common.QueryPageParam;
import com.lzy.entity.OperateLog;
import com.lzy.entity.Result;
import com.lzy.mapper.OperateLogMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * 操作日志控制器
 */
@RestController
@RequestMapping("/log")
public class LogController {
    
    private static final Logger log = LoggerFactory.getLogger(LogController.class);
    
    @Autowired
    private OperateLogMapper operateLogMapper;
    
    /**
     * 分页查询操作日志
     * @param query 查询参数
     * @return 查询结果
     */
    @PostMapping("/listPage")
    public Result listPage(@RequestBody QueryPageParam query) {
        log.info("分页查询操作日志");
        
        // 获取分页参数
        int pageNum = query.getPageNum();
        int pageSize = query.getPageSize();
        
        // 创建分页对象
        Page<OperateLog> page = new Page<>(pageNum, pageSize);
        
        // 获取查询参数
        HashMap<String, Object> param = (HashMap<String, Object>) query.getParam();
        
        // 执行查询
        IPage<OperateLog> pageData = operateLogMapper.selectPageByCondition(page, param);
        
        // 返回结果
        return Result.success(pageData.getRecords(), pageData.getTotal());
    }
} 